home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / ODUtils / TempRef.th < prev    next >
Encoding:
Text File  |  1996-09-17  |  2.0 KB  |  87 lines  |  [TEXT/MPS ]

  1. /*
  2. #    File:        TempRef.th
  3. #
  4. #    Contains:    Internal header for use by TempObj.h
  5. #
  6. #    Owned by:    Jens Alfke
  7. #
  8. #    Copyright:    © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
  9. #
  10. #    Change History (most recent first):
  11. #
  12. #         <2>     5/24/96    jpa        1322106: Add operator "&" so taking address
  13. #                                    works as expected. 1246074:
  14. #                                    Native-exception optimizations.
  15. #    
  16. #    In Progress:
  17.         
  18. */
  19.  
  20. // This header is a utility used by TempObj.h. Do not include it directly unless you
  21. // really know what you're doing -- see the Tech Note "Temporary Objects/References".
  22.  
  23. #ifndef SOM_ODDocument_xh
  24. #include <Document.xh>
  25. #endif
  26.  
  27. #ifndef _T_
  28. #error _T_ must be defined before including a .th file
  29. #endif
  30. #ifndef _C_
  31. #error _C_ must be defined before including a .th file
  32. #endif
  33.  
  34. //===========================================================================
  35. //    TempObj <T>
  36. //===========================================================================
  37.  
  38. #ifdef _TMPL_IMPL_
  39.  
  40.     // Implementation of the TempRef constructor/destructor.
  41.     // Used only if we don't use native exceptions.
  42.     _C_::_C_( _T_ *obj )
  43.     {
  44.         fObj = obj;
  45.     }
  46.  
  47.     _C_::~_C_( )
  48.     {
  49.         // Prevent compiler from inlining synthesized destructor
  50.         // which causes code bloat.
  51.     }
  52.  
  53. #else
  54.  
  55.     #if defined(__SC__) || defined(__MRC__)
  56.     // Some of the typecasts below offend certain compilers.
  57.     #pragma options(!warn_cast_incomplete_type)
  58.     #endif
  59.  
  60.     // Declaration of the TempRef class
  61.     class _C_ :public BaseTempRef
  62.     {
  63.         public:
  64. #ifdef _NATIVE_EXCEPTIONS_
  65.         _C_( _T_* t )                {fObj = (ODRefCntObject*)t;}
  66.         ~_C_( )                        { }
  67. #else
  68.         _C_( _T_* );
  69.         ~_C_( );
  70. #endif
  71.         _T_* operator-> ()            {return (_T_*)fObj;}
  72.         _T_** operator& ()            {return (_T_**)&fObj;}
  73.         operator _T_* ()            {return (_T_*)fObj;}
  74.         _T_* operator=( _T_ *t )    {fObj=(ODRefCntObject*)t; return t;}
  75.         
  76.         _T_* DontRelease()            {_T_* temp=(_T_*)fObj; fObj=kODNULL; return temp;}
  77.     };
  78.  
  79.     #if defined(__SC__) || defined(__MRC__)
  80.     #pragma options(warn_cast_incomplete_type)    // undo previous pragma
  81.     #endif
  82. #endif
  83.  
  84. #undef _T_
  85. #undef _C_
  86.  
  87.